package com.cxs.plan.controller.bill;

import com.cxs.plan.DTO.BillDTO;
import com.cxs.plan.domain.HttpResult;
import com.cxs.plan.domain.entity.Bill;
import com.cxs.plan.service.BillService;
import com.cxs.plan.service.UserService;
import com.cxs.plan.utils.BaseContext;
import com.cxs.plan.utils.SecurityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bill/manage")
public class ManageController {
    @Autowired
    private BillService billService;

    @Autowired
    private UserService userService;

    @GetMapping
    public HttpResult getBillList() {
        return HttpResult.success(billService.getBillList());
    }

    @PostMapping
    public HttpResult addBill(@RequestBody BillDTO billDTO) {
        billService.saveBill(billDTO);
        return HttpResult.success();
    }

    @PutMapping
    public HttpResult updateBill(@RequestBody BillDTO billDTO) {
        billService.updateBill(billDTO);
        return HttpResult.success();
    }
    @DeleteMapping
    public HttpResult deleteBill(@RequestParam Integer id) {
        billService.deleteBillById(id);
        return HttpResult.success();
    }

    @GetMapping("/{id}")
    public HttpResult getBill(@PathVariable Integer id) {
        return HttpResult.success(billService.getBillInfo(id));
    }

    @GetMapping("/user")
    public HttpResult getFilterUser(String name) {
        return HttpResult.success(userService.selectUserListByName(name));
    }

}
